package com.hzit.servlet;

import cn.hutool.core.util.StrUtil;
import com.hzit.entity.Classes;
import com.hzit.entity.R;
import com.hzit.entity.Student;
import com.hzit.service.IClassesService;
import com.hzit.service.IStudentService;
import com.hzit.utilt.ResponseUtil;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
	private IClassesService classesService;

	//1. 初始化得到当前studentService对象
	@Override
	public void init() throws ServletException {
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
		classesService = wac.getBean(IClassesService.class);
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("application/json;charset=utf8");
		List<Classes>  classes = classesService.findAll();
		ResponseUtil.out(resp,R.ok(classes));
	}

}
